package blue.datacenter2;

import org.zeromq.ZMQ;

/* ZMQ Publisher with bind. */
public class ZmqPublisher{
	private ZMQ.Context zmq_ctx_;
	private ZMQ.Socket zmq_sock_;	
	private String port_;

	public ZmqPublisher(String port){
        //  Prepare our context and publisher
        port_ = port;
        String endpoint = "tcp://*:"+port_;
        zmq_ctx_ = ZMQ.context(1);
        zmq_sock_ = zmq_ctx_.socket(ZMQ.PUB);
        System.out.println("Master open Publisher to "+endpoint);
        zmq_sock_.bind(endpoint);
	}

	public void publish(String msg){
        synchronized(this){
            zmq_sock_.send(msg, 0);
        }
	}

}